package m.jclecai.com.ui;

import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.text.Html;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.squareup.okhttp.Request;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;

import butterknife.OnClick;
import m.jclecai.com.R;
import m.jclecai.com.activity.LottoTrendActivity;
import m.jclecai.com.activity.WebHelperActivity;
import m.jclecai.com.adapter.BallsAdapter;
import m.jclecai.com.adapter.independentLotteryAdapter.PLS_SD_QXCA_LotteryAdapter;
import m.jclecai.com.base.BaseActivity;
import m.jclecai.com.bean.BallItem;
import m.jclecai.com.bean.IssueInfoBean;
import m.jclecai.com.bean.MissDataBean;
import m.jclecai.com.constant.Constant_Result;
import m.jclecai.com.constant.Constant_Url;
import m.jclecai.com.contents.LotteryType;
import m.jclecai.com.inter.IAdapterChange;
import m.jclecai.com.pop.FC3D_PLS_pupopWindow;
import m.jclecai.com.utils.BaseUtils;
import m.jclecai.com.utils.MakeRandomUtil;
import m.jclecai.com.utils.PreferenceUtil;
import m.jclecai.com.utils.ShakeUtils;
import m.jclecai.com.utils.ToastUtil;
import m.jclecai.com.utils.http.FastOk;
import m.jclecai.com.utils.http.HttpManager;
import m.jclecai.com.view.BallGridView;
import m.jclecai.com.view.common.BottomBar;
import m.jclecai.com.view.common.VeticalDrawerLayout;
import q.rorbin.badgeview.Badge;


/**
 * Created by hp on 2017/3/24.
 * PLW PLS SD QXC 选号页面
 */
public class BetPlS_PLW_SD_QXCActivity extends BaseActivity implements View.OnClickListener, IAdapterChange, AdapterView.OnItemClickListener {

    private String type;
    private TextView tv_hint;

    private BallsAdapter itemOneAdapter, itemTwoAdapter, itemThreeAdapter, itemFourAdapter, itemFiveAdapter, itemSixAdapter, itemSevenAdapter;
    private LinearLayout ll_item_one, ll_item_two, ll_item_three, ll_item_four, ll_item_five, ll_item_six, ll_item_seven;
    //位置标识
    private TextView tv_position_one, tv_position_two, tv_position_three, tv_position_four, tv_position_five, tv_position_six, tv_position_seven;
    //选号控件
    private BallGridView gridview_item_one, gridview_item_two, gridview_item_three, gridview_item_four, gridview_item_five, gridview_item_six, gridview_item_seven;
    //分割线
    private RelativeLayout line_one, line_two, line_three, line_four, line_five, line_six;
    //每一行球总数
    private int ballCount;
    //注数金额
    private TextView tv_number_money;
    //截止时间
    private TextView tv_date;
    //期号
    private TextView tv_term;

    private int countOne, countTwo, countThree, countFour, countFive, countSix, countSeven;

    private PopupWindow pop;
    private RelativeLayout rl_select_box;
    private TextView[] textViews;

    private List<String> codeOne = new LinkedList<>();
    private List<String> codeTwo = new LinkedList<>();
    private List<String> codeThree = new LinkedList<>();
    private List<String> codeFour = new LinkedList<>();
    private List<String> codeFive = new LinkedList<>();
    private List<String> codeSix = new LinkedList<>();
    private List<String> codeSeven = new LinkedList<>();


    //判断是否是单选
    private boolean isRadio;
    private ListView mLvHistory;
    private VeticalDrawerLayout mDrawerLayout;
    private View mIvDateUnfold;
    private PLS_SD_QXCA_LotteryAdapter mPLS_sd_qxca_lotteryAdapter;
    private TextView mTvMissData;
    private BottomBar mBottomBar;
    private FC3D_PLS_pupopWindow mCenterPupopWindow;
    private MissDataBean.Omission mOmission;

    //和值的计算注数
    int[] modeSumNum={1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 63, 69, 73, 75, 75, 73, 69, 63, 55, 45, 36, 28, 21, 15, 10, 6, 3, 1};
    private ShakeUtils mShakeUtils;


    @Override
    protected int getContentView() {
        return R.layout.btting_pls_activity;
    }


    @Override
    protected void onResume() {
        super.onResume();
        // tv_number_money.setText(Html.fromHtml("共" + 0 + "注，<font color=red>" + 0 + "</font>元"));
        mShakeUtils.register();
    }

    @Override
    protected void initView() {

        Intent intent = getIntent();
        type = intent.getStringExtra("type");

        leftOptionText("");
        rightOptionText("",R.drawable.action_menu);
        ImageView iv_shake = (ImageView) findViewById(R.id.iv_shake);
        iv_shake.setOnClickListener(this);
        tv_hint = (TextView) findViewById(R.id.tv_hint);
        tv_number_money = (TextView) findViewById(R.id.tv_number_money);

        tv_term = (TextView) findViewById(R.id.tv_term);
        tv_date = (TextView) findViewById(R.id.tv_date);



        Button bt_bottom_left = (Button) findViewById(R.id.bt_bottom_left);
        bt_bottom_left.setOnClickListener(this);

        Button bt_bottom_right = (Button) findViewById(R.id.bt_bottom_right);

        //============这里新增加的一个View===================
        mBottomBar = ((BottomBar) findViewById(R.id.bottom_bar));
        mBottomBar.setLeftButtonClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //这里我们要实现的是机选和清空的逻辑
                //这里实现机选和清空的操作；
                TextView textView = (TextView) v;
                String text = textView.getText().toString();
                if ("机选".equals(text)) {
                    //随机选中一个
                    randomSelect();
                    textView.setText("清空");
                } else {
                    //清空逻辑；
                    clearBall();
                    textView.setText("机选");
                }
            }
        });
        mBottomBar.setRightButtonClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //下一步的逻辑
                isTo = true;
                if (type.equals("sd") || type.equals("pls")) {
                    if (ballNumber.size() > 0 && codeOne.size() == 0 && codeTwo.size() == 0 && codeThree.size() == 0) {
                        toActivity();
                    } else if (ballNumber.size() == 0 && codeOne.size() == 0 && codeTwo.size() == 0 && codeThree.size() == 0) {
                        randomSelect();
                    } else {
                        restrict = true;
                    }
                } else if (type.equals("plw")) {
                    if (ballNumber.size() > 0 && codeOne.size() == 0 && codeTwo.size() == 0 && codeThree.size() == 0 && codeFour.size() == 0 && codeFive.size() == 0) {
                        toActivity();
                    } else if (ballNumber.size() == 0 && codeOne.size() == 0 && codeTwo.size() == 0 && codeThree.size() == 0 && codeFour.size() == 0 && codeFive.size() == 0) {
                        randomSelect();
                    } else {
                        restrict = true;
                    }
                } else if (type.equals("qxc")) {
                    if (ballNumber.size() > 0 && codeOne.size() == 0 && codeTwo.size() == 0 && codeThree.size() == 0 && codeFour.size() == 0 && codeFive.size() == 0 && codeSix.size() == 0 && codeSeven.size() == 0) {
                        toActivity();
                    } else if (ballNumber.size() == 0 && codeOne.size() == 0 && codeTwo.size() == 0 && codeThree.size() == 0 && codeFour.size() == 0 && codeFive.size() == 0 && codeSix.size() == 0 && codeSeven.size() == 0) {
                        randomSelect();
                    } else {
                        restrict = true;
                    }
                }
                if (restrict) {
                    addAllSelectToBetting();
                }
                isTo = false;
                restrict = false;
            }
        });
        mBottomBar.setCenterButtonClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //添加到购物车的逻辑
                addAllSelectToBetting();
            }
        });

        mBottomBar.setOnDragstateChangeListener(new Badge.OnDragStateChangedListener() {
            @Override
            public void onDragStateChanged(int dragState, Badge badge, View targetView) {
                if (dragState == Badge.OnDragStateChangedListener.STATE_SUCCEED) {
                    //这里表示成功，我们是需要清空所有的注数的
                    clearAllBetting();
                }
            }
        });

        mLvHistory = ((ListView) findViewById(R.id.lv_history));
        mLvHistory.setDivider(null);
        mDrawerLayout = ((VeticalDrawerLayout) findViewById(R.id.drawer_layout));
        mIvDateUnfold = findViewById(R.id.iv_date_unfold);

        mDrawerLayout.setOnDragStatusChange(new VeticalDrawerLayout.OnDragStatusChange() {
            @Override
            public void onOpen() {

            }

            @Override
            public void onClose() {

            }

            @Override
            public void OnDrag(float percent) {
                if (percent >= 0 && percent <= 1) {
                    Float evaluate = BaseUtils.evaluate(percent, 0, 180);
                    mIvDateUnfold.setRotation(evaluate);
                }
            }
        });
        mIvDateUnfold.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mDrawerLayout.toggle();
            }
        });


        //初始化小球的资源id；
        initBallView();

        //初始化中间的弹窗；
        initCenterPopupWindow();

    }

    private void initCenterPopupWindow() {
        //这里我们要做的一个事情就是；
        if(type.equals("pls")|| type.equals("sd")){
            setTitle("", R.drawable.gs);

            mCenterPupopWindow = new FC3D_PLS_pupopWindow(this);

            rl_select_box = mCenterPupopWindow.getViewById(R.id.rl_select_box);
            TextView tv_select_box_one = mCenterPupopWindow.getViewById(R.id.tv_select_box_one);
            tv_select_box_one.setText("直选");
            tv_select_box_one.setBackgroundResource(R.drawable.select_box_down);
            tv_select_box_one.setOnClickListener(this);

            TextView tv_select_box_two = mCenterPupopWindow.getViewById(R.id.tv_select_box_two);
            tv_select_box_two.setText("组三单式");
            tv_select_box_two.setOnClickListener(this);

            TextView tv_select_box_three = mCenterPupopWindow.getViewById(R.id.tv_select_box_three);
            tv_select_box_three.setText("组三复式");
            tv_select_box_three.setOnClickListener(this);

            TextView tv_select_box_four = mCenterPupopWindow.getViewById(R.id.tv_select_box_four);
            tv_select_box_four.setText("组六");
            tv_select_box_four.setOnClickListener(this);


            TextView tv_select_box_five = mCenterPupopWindow.getViewById(R.id.tv_select_box_five);
            tv_select_box_five.setText("和值");
            tv_select_box_five.setOnClickListener(this);

            textViews = new TextView[]{tv_select_box_one, tv_select_box_two, tv_select_box_three, tv_select_box_four,tv_select_box_five};


            TextView tv_select_box_six = mCenterPupopWindow.getViewById(R.id.tv_select_box_six);
            tv_select_box_six.setVisibility(View.INVISIBLE);

            mCenterPupopWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
                @Override
                public void onDismiss() {
                    //这里我们将关闭动画；
                    ObjectAnimator.ofFloat(ivTitleIcon, "rotation", 180, 360).setDuration(300).start();
                }
            });

        }

    }


    private void initBallView() {

        tv_position_one = (TextView) findViewById(R.id.tv_position_one);
        tv_position_two = (TextView) findViewById(R.id.tv_position_two);
        tv_position_three = (TextView) findViewById(R.id.tv_position_three);
        tv_position_four = (TextView) findViewById(R.id.tv_position_four);
        tv_position_five = (TextView) findViewById(R.id.tv_position_five);
        tv_position_six = (TextView) findViewById(R.id.tv_position_six);
        tv_position_seven = (TextView) findViewById(R.id.tv_position_seven);


        ll_item_one = (LinearLayout) findViewById(R.id.ll_item_one);
        ll_item_two = (LinearLayout) findViewById(R.id.ll_item_two);
        ll_item_three = (LinearLayout) findViewById(R.id.ll_item_three);
        ll_item_four = (LinearLayout) findViewById(R.id.ll_item_four);
        ll_item_five = (LinearLayout) findViewById(R.id.ll_item_five);
        ll_item_six = (LinearLayout) findViewById(R.id.ll_item_six);
        ll_item_seven = (LinearLayout) findViewById(R.id.ll_item_seven);

        line_one = (RelativeLayout) findViewById(R.id.line_one);
        line_two = (RelativeLayout) findViewById(R.id.line_two);
        line_three = (RelativeLayout) findViewById(R.id.line_three);
        line_four = (RelativeLayout) findViewById(R.id.line_four);
        line_five = (RelativeLayout) findViewById(R.id.line_five);
        line_six = (RelativeLayout) findViewById(R.id.line_six);


        gridview_item_one = (BallGridView) findViewById(R.id.gridview_item_one);
        itemOneAdapter = new BallsAdapter(this);
        gridview_item_one.setOnItemClickListener(this);

        gridview_item_two = (BallGridView) findViewById(R.id.gridview_item_two);
        itemTwoAdapter = new BallsAdapter(this);
        gridview_item_two.setOnItemClickListener(this);

        gridview_item_three = (BallGridView) findViewById(R.id.gridview_item_three);
        itemThreeAdapter = new BallsAdapter(this);
        gridview_item_three.setOnItemClickListener(this);

        gridview_item_four = (BallGridView) findViewById(R.id.gridview_item_four);
        itemFourAdapter = new BallsAdapter(this);
        gridview_item_four.setOnItemClickListener(this);

        gridview_item_five = (BallGridView) findViewById(R.id.gridview_item_five);
        itemFiveAdapter = new BallsAdapter(this);
        gridview_item_five.setOnItemClickListener(this);

        gridview_item_six = (BallGridView) findViewById(R.id.gridview_item_six);
        itemSixAdapter = new BallsAdapter(this);
        gridview_item_six.setOnItemClickListener(this);

        gridview_item_seven = (BallGridView) findViewById(R.id.gridview_item_seven);
        itemSevenAdapter = new BallsAdapter(this);
        gridview_item_seven.setOnItemClickListener(this);

    }


    private void initPopupView() {
        View pv = View.inflate(this, R.layout.lottery_help_popupview, null);
        pop = new PopupWindow(pv, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        TextView tv_trendChart = (TextView) pv.findViewById(R.id.tv_trendChart);
        tv_trendChart.setOnClickListener(this);
        TextView tv_kaijiang = (TextView) pv.findViewById(R.id.tv_kaijiang);

        mTvMissData = (TextView) pv.findViewById(R.id.tv_missData);
        mTvMissData.setOnClickListener(this);
        pv.findViewById(R.id.tv_play_desc).setOnClickListener(this);

        boolean showMissing = PreferenceUtil.isShowMissing(this);
        if (showMissing) {
            //这里表示显示；
            showMissData();
        } else {
            hideMissData();
        }


        tv_kaijiang.setOnClickListener(this);
        pop.setBackgroundDrawable(new BitmapDrawable());
        pop.setFocusable(true);
        pop.setOutsideTouchable(true);
    }

    @Override
    protected void initData() {

        mShakeUtils = new ShakeUtils(this);
        mShakeUtils.setOnShakeUtilsListener(new ShakeUtils.OnShakeUtilsListener() {
            @Override
            public void onShakedListener() {
                randomSelect();
            }

            @Override
            public void hasNotVibratorListener() {

            }
        });

        if (type.equals("pls") || type.equals("sd")) {
            number = 3;

            ll_item_one.setVisibility(View.VISIBLE);
            ll_item_two.setVisibility(View.VISIBLE);
            ll_item_three.setVisibility(View.VISIBLE);
            line_one.setVisibility(View.VISIBLE);
            line_two.setVisibility(View.VISIBLE);

            tv_position_one.setText("百位");
            tv_position_two.setText("十位");
            tv_position_three.setText("个位");

            ballCount = 9;
            if (type.equals("sd")) {
                setTitle("福彩3D");
            } else {
                setTitle("排列三");
            }

            tv_hint.setText("每位至少选择1个号码");
            gridview_item_one.setAdapter(itemOneAdapter);
            gridview_item_two.setAdapter(itemTwoAdapter);
            gridview_item_three.setAdapter(itemThreeAdapter);
            //这里是我们增加和值的地方的东西；
            gridview_item_four.setAdapter(itemFourAdapter);

        } else if (type.equals("plw")) {
            number = 5;

            ll_item_one.setVisibility(View.VISIBLE);
            ll_item_two.setVisibility(View.VISIBLE);
            ll_item_three.setVisibility(View.VISIBLE);
            ll_item_four.setVisibility(View.VISIBLE);
            ll_item_five.setVisibility(View.VISIBLE);

            line_one.setVisibility(View.VISIBLE);
            line_two.setVisibility(View.VISIBLE);
            line_three.setVisibility(View.VISIBLE);
            line_four.setVisibility(View.VISIBLE);

            tv_position_one.setText("万位");
            tv_position_two.setText("千位");
            tv_position_three.setText("百位");
            tv_position_four.setText("十位");
            tv_position_five.setText("个位");

            ballCount = 9;
            setTitle("排列五");
            tv_hint.setText("每位至少选择1个号码");

            gridview_item_one.setAdapter(itemOneAdapter);
            gridview_item_two.setAdapter(itemTwoAdapter);
            gridview_item_three.setAdapter(itemThreeAdapter);
            gridview_item_four.setAdapter(itemFourAdapter);
            gridview_item_five.setAdapter(itemFiveAdapter);
        } else if (type.equals("qxc")) {
            number = 7;
            ll_item_one.setVisibility(View.VISIBLE);
            ll_item_two.setVisibility(View.VISIBLE);
            ll_item_three.setVisibility(View.VISIBLE);
            ll_item_four.setVisibility(View.VISIBLE);
            ll_item_five.setVisibility(View.VISIBLE);
            ll_item_six.setVisibility(View.VISIBLE);
            ll_item_seven.setVisibility(View.VISIBLE);

            line_one.setVisibility(View.VISIBLE);
            line_two.setVisibility(View.VISIBLE);
            line_three.setVisibility(View.VISIBLE);
            line_four.setVisibility(View.VISIBLE);
            line_six.setVisibility(View.VISIBLE);
            line_five.setVisibility(View.VISIBLE);

            tv_position_one.setText("一");
            tv_position_two.setText("二");
            tv_position_three.setText("三");
            tv_position_four.setText("四");
            tv_position_five.setText("五");
            tv_position_six.setText("六");
            tv_position_seven.setText("七");

            ballCount = 9;
            setTitle("七星彩");
            tv_hint.setText("每位至少选择1个号码");

            gridview_item_one.setAdapter(itemOneAdapter);
            gridview_item_two.setAdapter(itemTwoAdapter);
            gridview_item_three.setAdapter(itemThreeAdapter);
            gridview_item_four.setAdapter(itemFourAdapter);
            gridview_item_five.setAdapter(itemFiveAdapter);
            gridview_item_six.setAdapter(itemSixAdapter);
            gridview_item_seven.setAdapter(itemSevenAdapter);

        }
        //这里是显示小球的位置；
        initBallList();

        initPopupView();
        getMissData(type);
        getIssueInfo(type);
    }

    private void getMissData(String type) {
        //showDialog();

        HashMap<String, String> params = new HashMap<>();
        params.put("type",type);

        HttpManager.postAsyn(Constant_Url.GET_MISS_DATA, new HttpManager.StringCallback() {
            @Override
            public void onFailure(Request request, IOException e) {

                ToastUtil.showToast(BetPlS_PLW_SD_QXCActivity.this, R.string.connect_failure);
                e.printStackTrace();
            }

            @Override
            public void onResponse(String response) {

                try {

                    MissDataBean bean = FastOk.get(response, MissDataBean.class);
                    if (bean != null) {
                        setMissData(bean);
                    }

                } catch (Exception e) {
                    e.printStackTrace();
                    //捕获异常
                    DisPlay("网络异常！");
                }

            }
        },params);
    }


    private void getIssueInfo(String type) {

        HashMap<String, String> paramsMap = new HashMap<>();
        paramsMap.put("type",type);

        HttpManager.postAsyn(Constant_Url.ISSUE_INFO, new HttpManager.StringCallback() {
            @Override
            public void onFailure(Request request, IOException e) {
                DisPlay("网络异常！");
                e.printStackTrace();
            }

            @Override
            public void onResponse(String response) {
                IssueInfoBean bean = FastOk.get(response, IssueInfoBean.class);
                if(bean!=null){
                    setViewInfo(bean);
                }
            }
        },paramsMap);

/*        OkHttpClientManager.Param Url = new OkHttpClientManager.Param("url", Constant_Url.ISSUE_INFO);
        OkHttpClientManager.Param Type = new OkHttpClientManager.Param("type", type);
        OkHttpClientManager.Param[] param = new OkHttpClientManager.Param[]{Url, Type};
        try {
            OkHttpClientManager.getInstance().asynPost(new OnResultCallback() {
                @Override
                public void onGetResult(String json) {
                    IssueInfoBean bean = FastOk.get(json, IssueInfoBean.class);
                    setViewInfo(bean);
                }

                @Override
                public void onError() {
                    ToastUtil.showToast(BetPlS_PLW_SD_QXCActivity.this, R.string.connect_failure);
                }
            }, param);
        } catch (IOException e) {
            e.printStackTrace();
        }*/
    }

    private void setViewInfo(IssueInfoBean bean) {
        if (bean == null) return;
        tv_term.setText(Html.fromHtml("期号:<font color=red>" + bean.getTermNo() + "</font>"));
       // tv_date.setText("截止时间:" + bean.getStopSaleTime());
        tv_date.setText(Html.fromHtml("截止时间:<font color=red>" + bean.getStopSaleTime() + "</font>"));
    }


    private void initBallList() {

        //每个位置球数
        int one = 0;
        int two = 0;
        int three = 0;
        int four = 0;
        int five = 0;
        int six = 0;
        int seven = 0;
        //球item
        BallItem ballItem = null;

        if (type.equals("pls") || type.equals("plw") || type.equals("qxc") || type.equals("sd")) {


            while (true) {
                if (one > ballCount) {
                    break;
                }
                ballItem = new BallItem("" + one, false, true);
                itemOneAdapter.addItem(ballItem);
                one++;
            }

            while (true) {
                if (two > ballCount) {
                    break;
                }
                ballItem = new BallItem("" + two, false, true);
                itemTwoAdapter.addItem(ballItem);
                two++;
            }

            while (true) {
                if (three > ballCount) {
                    break;
                }
                ballItem = new BallItem("" + three, false, true);
                itemThreeAdapter.addItem(ballItem);
                three++;
            }
            //==========和值比较特殊============
            if(type.equals("pls")|| type.equals("sd")){
                while (true) {
                    if (four > 27) {
                        break;
                    }
                    ballItem = new BallItem("" + four, false, true);
                    itemFourAdapter.addItem(ballItem);
                    four++;
                }
            }
        }
        if (type.equals("plw") || type.equals("qxc")) {

            while (true) {
                if (four > ballCount) {
                    break;
                }
                ballItem = new BallItem("" + four, false, true);
                itemFourAdapter.addItem(ballItem);
                four++;
            }
            while (true) {
                if (five > ballCount) {
                    break;
                }
                ballItem = new BallItem("" + five, false, true);
                itemFiveAdapter.addItem(ballItem);
                five++;
            }
        }
        if (type.equals("qxc")) {

            while (true) {
                if (six > ballCount) {
                    break;
                }
                ballItem = new BallItem("" + six, false, true);
                itemSixAdapter.addItem(ballItem);
                six++;
            }
            while (true) {
                if (seven > ballCount) {
                    break;
                }
                ballItem = new BallItem("" + seven, false, true);
                itemSevenAdapter.addItem(ballItem);
                seven++;
            }
        }

        itemOneAdapter.notifyDataSetChanged();
        itemTwoAdapter.notifyDataSetChanged();
        itemThreeAdapter.notifyDataSetChanged();
        itemFourAdapter.notifyDataSetChanged();
        itemFiveAdapter.notifyDataSetChanged();
        itemSixAdapter.notifyDataSetChanged();
        itemSevenAdapter.notifyDataSetChanged();
    }


    /*
        private void initBallList(MissDataBean bean) {
            if (bean == null) return;
            MissDataBean.Omission omission = bean.getOmission();
            if (omission == null) return;
            //每个位置球数
            int one = 0;
            int two = 0;
            int three = 0;
            int four = 0;
            int five = 0;
            int six = 0;
            int seven = 0;
            //球item
            BallItem ballItem = null;

            if (type.equals("pls") || type.equals("plw") || type.equals("qxc") || type.equals("sd")) {
                String[] m0 = omission.getM0().split(",");
                String[] m1 = omission.getM1().split(",");
                String[] m2 = omission.getM2().split(",");

                while (true) {
                    if (one > ballCount) {
                        break;
                    }
                    ballItem = new BallItem("" + one, false, true, m0[one]);
                    itemOneAdapter.addItem(ballItem);
                    one++;
                }

                while (true) {
                    if (two > ballCount) {
                        break;
                    }
                    ballItem = new BallItem("" + two, false, true, m1[two]);
                    itemTwoAdapter.addItem(ballItem);
                    two++;
                }

                while (true) {
                    if (three > ballCount) {
                        break;
                    }
                    ballItem = new BallItem("" + three, false, true, m2[three]);
                    itemThreeAdapter.addItem(ballItem);
                    three++;
                }
            }
            if (type.equals("plw") || type.equals("qxc")) {
                String[] m3 = omission.getM3().split(",");
                String[] m4 = omission.getM4().split(",");
                while (true) {
                    if (four > ballCount) {
                        break;
                    }
                    ballItem = new BallItem("" + four, false, true, m3[four]);
                    itemFourAdapter.addItem(ballItem);
                    four++;
                }
                while (true) {
                    if (five > ballCount) {
                        break;
                    }
                    ballItem = new BallItem("" + five, false, true, m4[five]);
                    itemFiveAdapter.addItem(ballItem);
                    five++;
                }
            }
            if (type.equals("qxc")) {
                String[] m5 = omission.getM3().split(",");
                String[] m6 = omission.getM4().split(",");
                while (true) {
                    if (six > ballCount) {
                        break;
                    }
                    ballItem = new BallItem("" + six, false, true, m5[six]);
                    itemSixAdapter.addItem(ballItem);
                    six++;
                }
                while (true) {
                    if (seven > ballCount) {
                        break;
                    }
                    ballItem = new BallItem("" + seven, false, true, m6[seven]);
                    itemSevenAdapter.addItem(ballItem);
                    seven++;
                }
            }

            itemOneAdapter.notifyDataSetChanged();
            itemTwoAdapter.notifyDataSetChanged();
            itemThreeAdapter.notifyDataSetChanged();
            itemFourAdapter.notifyDataSetChanged();
            itemFiveAdapter.notifyDataSetChanged();
            itemSixAdapter.notifyDataSetChanged();
            itemSevenAdapter.notifyDataSetChanged();
        }
    */
    @OnClick(R.id.tv_right_option)
    void showMenu() {
        int height = rlBar.getHeight();
        int statusHeight = BaseUtils.getStatusHeight(this);
        int width = BaseUtils.getDisplaySize(this, "width");
        pop.showAtLocation(rlBar, 0, width, height + statusHeight);
    }

    @Override
    public void onClick(View v) {
        boolean showMissing = PreferenceUtil.isShowMissing(this);

        switch (v.getId()) {
            case R.id.iv_shake:
                randomSelect();
                break;
            case R.id.bt_bottom_left:
                clearBall();
                break;
            case R.id.tv_select_box_one:
                //直选遗漏，m0,m1,m2
                clearBall();
                setMode(0);
                isRadio = false;
                mCenterPupopWindow.dismiss();
                //重新设置遗漏
                itemOneAdapter.addMissDataInfo(mOmission.getM0());
                itemTwoAdapter.addMissDataInfo(mOmission.getM1());
                itemThreeAdapter.addMissDataInfo(mOmission.getM2());

                if(showMissing){
                    showMissData(false);
                }else{
                    hideMissData(false);
                }
                break;
            case R.id.tv_select_box_two:
                clearBall();
                setMode(1);
                isRadio = true;
                mCenterPupopWindow.dismiss();
                //组三单式，没有遗漏
                hideMissData(false);
                break;
            case R.id.tv_select_box_three:
                clearBall();
                setMode(2);
                isRadio = false;
                mCenterPupopWindow.dismiss();
                //组三复式：
                itemOneAdapter.addMissDataInfo(mOmission.getM4());

                if(showMissing){
                    showMissData(false);
                }else{
                    hideMissData(false);
                }

                break;
            case R.id.tv_select_box_four:
                clearBall();
                setMode(3);
                isRadio = false;
                mCenterPupopWindow.dismiss();
                //组六；
                itemOneAdapter.addMissDataInfo(mOmission.getM4());

                if(showMissing){
                    showMissData(false);
                }else{
                    hideMissData(false);
                }
                break;

            case R.id.tv_select_box_five:
                //这里是我们新增加的功能一个和值
                clearBall();
                setMode(4);
                isRadio = false;
                mCenterPupopWindow.dismiss();
                //组六；
                itemOneAdapter.addMissDataInfo(mOmission.getM6());

                if(showMissing){
                    showMissData(false);
                }else{
                    hideMissData(false);
                }
                break;
            case R.id.tv_trendChart:
                Intent intent = new Intent(this, LottoTrendActivity.class);
                if (type.equals("pls")) {
                    intent.putExtra("lotteryId", LotteryType.PLS);
                    intent.putExtra("title", "排列三");
                } else if (type.equals("plw")) {
                    intent.putExtra("lotteryId", LotteryType.PLW);
                    intent.putExtra("title", "排列五");
                } else if (type.equals("qxc")) {
                    intent.putExtra("lotteryId", LotteryType.QXC);
                    intent.putExtra("title", "七星彩");
                }else if(type.equals("sd")){
                    intent.putExtra("lotteryId", LotteryType.SD);
                    intent.putExtra("title", "福彩3D");
                }
                startActivity(intent);
                break;
            case R.id.tv_kaijiang:
                intent = new Intent(this, LotteryHistoryActivity.class);
                intent.putExtra("type", type);
                startActivity(intent);
                break;
            case R.id.tv_missData:
                //这里我们是需要根据本地保存的数据来决定是否显示遗漏
                showMissing = !showMissing;
                if (showMissing) {
                    showMissData();
                } else {
                    hideMissData();
                }
                pop.dismiss();
                break;
            case R.id.tv_play_desc:

                Intent helpIntent = new Intent(this, WebHelperActivity.class);
                helpIntent.putExtra("title", "玩法介绍");
                helpIntent.putExtra("code", type);
                helpIntent.putExtra("isLocal", true);
                startActivity(helpIntent);
                break;
        }
    }

    public void showMissData(boolean  isSave){
        //这里我们要拿到红色的和蓝色的adapter;

        if (type.equals("pls") || type.equals("plw") || type.equals("qxc") || type.equals("sd")) {
            if(this.modeState != 1){
                itemOneAdapter.showMissData();
                itemTwoAdapter.showMissData();
                itemThreeAdapter.showMissData();
                itemFourAdapter.showMissData();
            }
        }
        if (type.equals("plw") || type.equals("qxc")) {
            itemFourAdapter.showMissData();
            itemFiveAdapter.showMissData();
        }
        if (type.equals("qxc")) {
            itemSixAdapter.showMissData();
            itemSevenAdapter.showMissData();
        }


        if(isSave){
            //显示遗漏
            mTvMissData.setText("隐藏遗漏");
            PreferenceUtil.setIsShowMissing(this, true);
        }
    }


    public void showMissData() {
        showMissData(true);
    }

    public void hideMissData(boolean isSave){

        if (type.equals("pls") || type.equals("plw") || type.equals("qxc") || type.equals("sd")) {
            //防止在单式里面打开和隐藏遗漏
                itemOneAdapter.hideMissData();
                itemTwoAdapter.hideMissData();
                itemThreeAdapter.hideMissData();

                itemFourAdapter.hideMissData();
        }
        if (type.equals("plw") || type.equals("qxc")) {
            itemFourAdapter.hideMissData();
            itemFiveAdapter.hideMissData();
        }
        if (type.equals("qxc")) {
            itemSixAdapter.hideMissData();
            itemSevenAdapter.hideMissData();
        }
        if(isSave){
            //隐藏遗漏
            mTvMissData.setText("显示遗漏");
            PreferenceUtil.setIsShowMissing(this, false);
        }

    }

    public void hideMissData() {
        hideMissData(true);
    }


    //点击展开玩法选项卡
    @OnClick({R.id.tv_mid_title, R.id.iv_title_icon})
    void setNnfoldVisible() {
        if(type.equals("pls") || type.equals("sd")){
            mCenterPupopWindow.showAsDropDown(rlBar);
            ObjectAnimator.ofFloat(ivTitleIcon, "rotation", 0, 180).setDuration(300).start();
        }
    }

    private int modeState;

    private void setMode(int modeState) {
        this.modeState = modeState;
        clearBall();
        for (int i = 0; i < textViews.length; i++) {
            if (i == modeState) {
                textViews[i].setBackgroundResource(R.drawable.select_box_down);
            } else {
                textViews[i].setBackgroundResource(R.drawable.select_box_up);
            }
        }

        if (type.equals("pls") || type.equals("sd")) {
            if (modeState == 0) {
                number = 3;
                ll_item_one.setVisibility(View.VISIBLE);
                ll_item_two.setVisibility(View.VISIBLE);
                ll_item_three.setVisibility(View.VISIBLE);
                line_one.setVisibility(View.VISIBLE);
                line_two.setVisibility(View.VISIBLE);

                ll_item_four.setVisibility(View.GONE);

                tv_hint.setText("每位至少选1个号，按位猜对开奖号即中1040元");
                tv_position_one.setText("百位");
                tv_position_two.setText("十位");
                tv_position_three.setText("个位");
            } else if (modeState == 1) {
                number = 2;
                ll_item_one.setVisibility(View.VISIBLE);
                ll_item_two.setVisibility(View.VISIBLE);
                ll_item_three.setVisibility(View.GONE);
                line_two.setVisibility(View.GONE);

                ll_item_four.setVisibility(View.GONE);

                tv_hint.setText("选1个同号和1个不同,开奖号码有两个相同数字和1个其他数字,全部猜中(位置不限)即中346元");
                tv_position_one.setText("同号");
                tv_position_two.setText("不同");
            } else if (modeState == 2) {
                number = 2;
                ll_item_one.setVisibility(View.VISIBLE);

                ll_item_two.setVisibility(View.GONE);
                ll_item_three.setVisibility(View.GONE);
                line_two.setVisibility(View.GONE);
                ll_item_four.setVisibility(View.GONE);

                tv_hint.setText("至少选2个号,开奖号码2个相同数字和1个其他数字,全部猜中(位置不限)即中346元");
                tv_position_one.setText("选号");
            } else if (modeState == 3) {
                number = 3;

                ll_item_one.setVisibility(View.VISIBLE);

                ll_item_two.setVisibility(View.GONE);
                ll_item_three.setVisibility(View.GONE);
                line_two.setVisibility(View.GONE);

                ll_item_four.setVisibility(View.GONE);

                tv_hint.setText("至少选3个号,开奖号码3个数字全不同,全部猜中(位置不限)即中173元");
                tv_position_one.setText("选号");
            }else if(modeState == 4){
                //这里我们实现的功能就是和值界面的初始化；

                number = 3;

                ll_item_one.setVisibility(View.GONE);

                ll_item_two.setVisibility(View.GONE);
                ll_item_three.setVisibility(View.GONE);
                line_two.setVisibility(View.GONE);

                ll_item_four.setVisibility(View.VISIBLE);

                tv_hint.setText("猜中开奖号码之和,奖金1040元");
                tv_position_four.setText("选号");
            }
        }
    }

    @Override
    public View onItemChanged(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        BallItem ballItem = null;
        boolean selected = false;
        String num = null;
        String missData = null;
        int mViewGroup = 0;

        BallsAdapter ballsAdapter = null;

        if (parent.getId() == R.id.gridview_item_one) {
            ballItem = (BallItem) itemOneAdapter.getItem(position);
            ballsAdapter = itemOneAdapter;
        } else if (parent.getId() == R.id.gridview_item_two) {
            ballItem = (BallItem) itemTwoAdapter.getItem(position);
            ballsAdapter = itemTwoAdapter;
        } else if (parent.getId() == R.id.gridview_item_three) {
            ballItem = (BallItem) itemThreeAdapter.getItem(position);
            ballsAdapter = itemThreeAdapter;
        } else if (parent.getId() == R.id.gridview_item_four) {
            ballItem = (BallItem) itemFourAdapter.getItem(position);
            ballsAdapter = itemFourAdapter;
        } else if (parent.getId() == R.id.gridview_item_five) {
            ballItem = (BallItem) itemFiveAdapter.getItem(position);
            ballsAdapter = itemFiveAdapter;
        } else if (parent.getId() == R.id.gridview_item_six) {
            ballItem = (BallItem) itemSixAdapter.getItem(position);
            ballsAdapter = itemSixAdapter;
        } else if (parent.getId() == R.id.gridview_item_seven) {
            ballItem = (BallItem) itemSevenAdapter.getItem(position);
            ballsAdapter = itemSevenAdapter;
        }

        mViewGroup = R.layout.ballgridview_ball_item;

        if (null == convertView) {
            holder = new ViewHolder();
            LayoutInflater inflater = LayoutInflater.from(this);
            convertView = inflater.inflate(mViewGroup, parent, false);
            holder.ball_num = (TextView) convertView.findViewById(R.id.txt_ball_num);
            holder.tv_missData = (TextView) convertView.findViewById(R.id.tv_missData);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        //是否选中
        selected = ballItem.isSelected();
        num = ballItem.getBallNum();

/*        //遗漏数据
        missData = ballItem.getMissData();
        holder.tv_missData.setText(missData);*/

        holder.ball_num.setText(num);
        //设置遗漏
        if (ballsAdapter.getMissDataInfo().length > 0) {
            int index=position<ballsAdapter.getMissDataInfo().length?position:ballsAdapter.getMissDataInfo().length-1;
            holder.tv_missData.setText(ballsAdapter.getMissDataInfo()[index]);
        } else {
            holder.tv_missData.setText("-");
        }
        //这里我们通过判断本地文件来判断是否显示
        if (ballsAdapter.isShowMissData()) {
            holder.tv_missData.setVisibility(View.VISIBLE);
        } else {
            holder.tv_missData.setVisibility(View.GONE);
        }

        //判断球是否被选中
        if (selected) {
            holder.ball_num.setBackgroundResource(R.drawable.red_ball);
            holder.ball_num.setTextColor(Color.WHITE);
            startBallAnimation(holder.ball_num);
        } else {
            holder.ball_num.setBackgroundResource(R.drawable.shape_ball_red_bg);
            holder.ball_num.setTextColor(getResources().getColor(R.color.baseRed));
        }
        return convertView;
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

        if((type.equals("sd") || type.equals("pls")) && parent.getId() == R.id.gridview_item_four){
            //这里是我们新增的和值，来单独处理自己的逻辑；草泥马，瞎几把代码；
            BallItem item =(BallItem) itemFourAdapter.getItem(position);
            //重新状态；
            item.setSelected(!item.isSelected());
            if(item.isSelected()){
                //这里我们需要添加的；
                codeOne.add(item.getBallNum());
            }else{
                codeOne.remove(item.getBallNum());
            }

            itemFourAdapter.notifyDataSetChanged();

            setNumberMoney(0,0,0,0,0,0,0);
        }else{
            //这里是之前的代码
            boolean oneIsSelect = false;
            boolean twoIsSelect = false;
            BallItem ballItemOne = (BallItem) itemOneAdapter.getItem(position);
            BallItem ballItemTwo = (BallItem) itemTwoAdapter.getItem(position);

            if (parent.getId() == R.id.gridview_item_one) {
                //判断是否是直选
                if (isRadio) {
                    //判断item2是否有选中的
                    if (codeTwo.size() > 0) {
                        for (int i = 0; i < codeTwo.size(); i++) {
                            //item2选中和item1选中的作比较,相同则去除item2添加itme1
                            if (ballItemOne.getBallNum().equals(codeTwo.get(i))) {
                                ballItemTwo.setSelected(false);
                                countTwo--;
                                codeTwo.remove(ballItemTwo.getBallNum());


                                for (int j = 0; j < itemOneAdapter.getCount(); j++) {
                                    BallItem item = (BallItem) itemOneAdapter.getItem(j);
                                    if (item.isSelected()) {
                                        item.setSelected(false);
                                        countOne--;
                                        codeOne.remove(item.getBallNum());
                                    }
                                }

                                ballItemOne.setSelected(true);
                                countOne++;
                                codeOne.add(ballItemOne.getBallNum());
                                break;
                                //点击的item2和item1不匹配
                            } else {
                                if (i == codeTwo.size() - 1) {
                                    oneIsSelect = true;
                                }
                            }
                        }
                    } else { //item1中没有选中的
                        oneIsSelect = true;
                    }
                    //单选
                    if (oneIsSelect) {
                        if (ballItemOne.isSelected()) {
                            ballItemOne.setSelected(false);
                            countOne--;
                            codeOne.remove(ballItemOne.getBallNum());
                        } else {
                            for (int j = 0; j < itemOneAdapter.getCount(); j++) {
                                BallItem item = (BallItem) itemOneAdapter.getItem(j);
                                if (item.isSelected()) {
                                    item.setSelected(false);
                                    countOne--;
                                    codeOne.remove(item.getBallNum());
                                }
                            }
                            ballItemOne.setSelected(true);
                            countOne++;
                            codeOne.add(ballItemOne.getBallNum());
                        }
                    }
                    itemOneAdapter.notifyDataSetChanged();
                    itemTwoAdapter.notifyDataSetChanged();
                    //非单选
                } else {
                    if (ballItemOne.isSelected()) {
                        ballItemOne.setSelected(false);
                        countOne--;
                        codeOne.remove(ballItemOne.getBallNum());
                    } else {
                        ballItemOne.setSelected(true);
                        countOne++;
                        codeOne.add(ballItemOne.getBallNum());
                    }
                    itemOneAdapter.notifyDataSetChanged();
                }
                setNumberMoney(countOne, countTwo, countThree, countFour, countFive, countSix, countSeven);
            } else if (parent.getId() == R.id.gridview_item_two) {
                if (isRadio) {
                    if (codeOne.size() > 0) {
                        for (int i = 0; i < codeOne.size(); i++) {
                            if (ballItemTwo.getBallNum().equals(codeOne.get(i))) {
                                ballItemOne.setSelected(false);
                                countOne--;
                                codeOne.remove(ballItemOne.getBallNum());

                                for (int j = 0; j < itemTwoAdapter.getCount(); j++) {
                                    BallItem item = (BallItem) itemTwoAdapter.getItem(j);
                                    if (item.isSelected()) {
                                        item.setSelected(false);
                                        countTwo--;
                                        codeTwo.remove(item.getBallNum());
                                    }
                                }

                                ballItemTwo.setSelected(true);
                                countTwo++;
                                codeTwo.add(ballItemTwo.getBallNum());
                                break;
                            } else {
                                if (i == codeOne.size() - 1) {
                                    twoIsSelect = true;
                                }
                            }
                        }
                    } else { //item1中没有选中的
                        twoIsSelect = true;
                    }

                    if (twoIsSelect) {
                        if (ballItemTwo.isSelected()) {
                            ballItemTwo.setSelected(false);
                            countTwo--;
                            codeTwo.remove(ballItemTwo.getBallNum());
                        } else {
                            for (int j = 0; j < itemTwoAdapter.getCount(); j++) {
                                BallItem item = (BallItem) itemTwoAdapter.getItem(j);
                                if (item.isSelected()) {
                                    item.setSelected(false);
                                    countTwo--;
                                    codeTwo.remove(item.getBallNum());
                                }
                            }
                            ballItemTwo.setSelected(true);
                            countTwo++;
                            codeTwo.add(ballItemTwo.getBallNum());
                        }
                    }
                    itemOneAdapter.notifyDataSetChanged();
                    itemTwoAdapter.notifyDataSetChanged();
                    //非单选
                } else {
                    if (ballItemTwo.isSelected()) {
                        ballItemTwo.setSelected(false);
                        countTwo--;
                        codeTwo.remove(ballItemTwo.getBallNum());
                    } else {
                        ballItemTwo.setSelected(true);
                        countTwo++;
                        codeTwo.add(ballItemTwo.getBallNum());
                    }
                    itemTwoAdapter.notifyDataSetChanged();
                }
                setNumberMoney(countOne, countTwo, countThree, countFour, countFive, countSix, countSeven);

                //item = 第三行
            } else if (parent.getId() == R.id.gridview_item_three) {
                BallItem ballItemThree = (BallItem) itemThreeAdapter.getItem(position);
                if (ballItemThree.isSelected()) {
                    ballItemThree.setSelected(false);
                    countThree--;
                    codeThree.remove(ballItemThree.getBallNum());
                } else {
                    ballItemThree.setSelected(true);
                    countThree++;
                    codeThree.add(ballItemThree.getBallNum());
                }
                setNumberMoney(countOne, countTwo, countThree, countFour, countFive, countSix, countSeven);
                itemThreeAdapter.notifyDataSetChanged();
            } else if (parent.getId() == R.id.gridview_item_four) {
                BallItem ballItemFour = (BallItem) itemFourAdapter.getItem(position);
                if (!ballItemFour.isSelected()) {
                    ballItemFour.setSelected(true);
                    countFour++;
                    codeFour.add(ballItemFour.getBallNum());
                } else {
                    ballItemFour.setSelected(false);
                    countFour--;
                    codeFour.remove(ballItemFour.getBallNum());
                }
                setNumberMoney(countOne, countTwo, countThree, countFour, countFive, countSix, countSeven);
                itemFourAdapter.notifyDataSetChanged();
            } else if (parent.getId() == R.id.gridview_item_five) {
                BallItem ballItemFive = (BallItem) itemFiveAdapter.getItem(position);
                if (!ballItemFive.isSelected()) {
                    ballItemFive.setSelected(true);
                    countFive++;
                    codeFive.add(ballItemFive.getBallNum());
                } else {
                    ballItemFive.setSelected(false);
                    countFive--;
                    codeFive.remove(ballItemFive.getBallNum());
                }
                setNumberMoney(countOne, countTwo, countThree, countFour, countFive, countSix, countSeven);
                itemFiveAdapter.notifyDataSetChanged();
            } else if (parent.getId() == R.id.gridview_item_six) {
                BallItem ballItemSix = (BallItem) itemSixAdapter.getItem(position);
                if (!ballItemSix.isSelected()) {
                    ballItemSix.setSelected(true);
                    countSix++;
                    codeSix.add(ballItemSix.getBallNum());
                } else {
                    ballItemSix.setSelected(false);
                    countSix--;
                    codeSix.remove(ballItemSix.getBallNum());
                }
                setNumberMoney(countOne, countTwo, countThree, countFour, countFive, countSix, countSeven);
                itemSixAdapter.notifyDataSetChanged();
            } else if (parent.getId() == R.id.gridview_item_seven) {
                BallItem ballItemSeven = (BallItem) itemSevenAdapter.getItem(position);
                if (!ballItemSeven.isSelected()) {
                    ballItemSeven.setSelected(true);
                    countSeven++;
                    codeSeven.add(ballItemSeven.getBallNum());
                } else {
                    ballItemSeven.setSelected(false);
                    countSeven--;
                    codeSeven.remove(ballItemSeven.getBallNum());
                }
                setNumberMoney(countOne, countTwo, countThree, countFour, countFive, countSix, countSeven);
                itemSevenAdapter.notifyDataSetChanged();
            }
        }


        //这里的我们要判断一下是否有相关的操作；
        if (codeOne.size() > 0 || codeTwo.size() > 0
                || codeThree.size() > 0 || codeFour.size() > 0
                || codeFive.size() > 0 || codeSix.size() > 0
                || codeSeven.size() > 0
                ) {
            //只要有任何一个size大于0
            mBottomBar.setLeftText("清空");
        } else {
            mBottomBar.setLeftText("机选");
        }
    }

    int num = 0;
    int money = 0;

    //设置投注金额
    private void setNumberMoney(int one, int two, int three, int four, int five, int six, int seven) {

        Log.i(TAG, "one=" + one);
        Log.i(TAG, "two=" + two);
        Log.i(TAG, "three=" + three);
        Log.i(TAG, "four=" + four);
        Log.i(TAG, "five=" + five);
        Log.i(TAG, "six=" + six);
        Log.i(TAG, "seven=" + seven);


        if (type.equals("pls") || type.equals("sd")) {

            switch (modeState) {
                //直选
                case 0:
                    num = one * two * three;
                    money = num * 2;
                    break;
                //组三单式
                case 1:
                    num = one * two;
                    money = num * 2;
                    break;
                //组三复式
                case 2:
                    num = countOne * (countOne - 1);
                    money = num * 2;
                    break;
                //组六
                case 3:
                    num = BaseUtils.math2(one, 3);
                    money = num * 2;
                    break;
                case 4:
                    //num=;
                    num=0;
                    for (String s : codeOne) {
                        int i = Integer.parseInt(s);
                        num+=modeSumNum[i];
                    }
                    money = num * 2;
                    break;
            }

        } else if (type.equals("plw")) {
            num = one * two * three * four * five;
            money = num * 2;
        } else if (type.equals("qxc")) {
            num = one * two * three * four * five * six * seven;
            money = num * 2;
        }
        //tv_number_money.setText(Html.fromHtml("共" + num + "注，<font color=red>" + money + "</font>元"));
        tv_number_money.setVisibility(View.VISIBLE);

        if (num > 0) {
            tv_number_money.setVisibility(View.VISIBLE);
            tv_number_money.setText(num + "注 , " + money + "元");
        } else {
            tv_number_money.setVisibility(View.INVISIBLE);
        }
        Log.i(TAG, "num=" + num);
        Log.i(TAG, "money=" + money);

    }

    private List<String> randomBallOne = new LinkedList<>();
    private List<String> randomBallTwo = new LinkedList<>();
    private List<String> randomBallThree = new LinkedList<>();
    private List<String> randomBallFour = new LinkedList<>();
    private List<String> randomBallFive = new LinkedList<>();
    private List<String> randomBallSix = new LinkedList<>();
    private List<String> randomBallSeven = new LinkedList<>();

    /**
     * @category 机选
     */
    private void randomSelect() {
        clearBall();

        if (type.equals("pls") || type.equals("sd")) {
            switch (modeState) {
                //直选
                case 0:
                    Log.i(TAG, "直选");
                    randomBallOne = MakeRandomUtil.getBall(10);
                    randomBallTwo = MakeRandomUtil.getBall(10);
                    randomBallThree = MakeRandomUtil.getBall(10);
                    codeOne.add(randomBallOne.get(0));
                    codeTwo.add(randomBallTwo.get(0));
                    codeThree.add(randomBallThree.get(0));

                    for (int i = 0; i < itemTwoAdapter.getCount(); i++) {
                        BallItem ballItemTwo = (BallItem) itemTwoAdapter.getItem(i);
                        if (ballItemTwo.getBallNum().equals(randomBallTwo.get(0))) {
                            ballItemTwo.setSelected(true);
                            break;
                        }
                    }
                    for (int i = 0; i < itemThreeAdapter.getCount(); i++) {
                        BallItem ballItemThree = (BallItem) itemThreeAdapter.getItem(i);
                        if (ballItemThree.getBallNum().equals(randomBallThree.get(0))) {
                            ballItemThree.setSelected(true);
                            break;
                        }
                    }
                    break;
                //组三单式
                case 1:
                    Log.i(TAG, "组三单式");
                    randomBallOne = MakeRandomUtil.getBall(10);
                    randomBallTwo = MakeRandomUtil.getBall(10);
                    int one = Integer.parseInt(randomBallOne.get(0));
                    int two = Integer.parseInt(randomBallTwo.get(0));
                    if (one == two) {
                        if (one < 10 && two+1<10) {
                            two++;
                        } else {
                            two--;
                        }
                    }
                    codeOne.add(randomBallOne.get(0));
                    codeTwo.add(two + "");
                    for (int i = 0; i < itemTwoAdapter.getCount(); i++) {
                        BallItem ballItemTwo = (BallItem) itemTwoAdapter.getItem(i);
                        if (ballItemTwo.getBallNum().equals(two + "")) {
                            ballItemTwo.setSelected(true);
                            break;
                        }
                    }
                    break;
                //组三复式
                case 2:
                    Log.i(TAG, "组三复式");
                    randomBallOne = MakeRandomUtil.getWeiBall(10, 2);
                    for (int i = 0; i < randomBallOne.size(); i++) {
                        codeOne.add(randomBallOne.get(i));
                    }
                    break;
                //组六
                case 3:
                    randomBallOne = MakeRandomUtil.getWeiBall(10, 3);
                    for (int i = 0; i < randomBallOne.size(); i++) {
                        codeOne.add(randomBallOne.get(i));
                    }
                    break;
                case 4:
                    randomBallOne = MakeRandomUtil.getWeiBall(27, 1);
                    for (int i = 0; i < randomBallOne.size(); i++) {
                        String s = randomBallOne.get(i);
                        codeOne.add(s);
                        BallItem item = (BallItem) itemFourAdapter.getItem(Integer.parseInt(s));
                        item.setSelected(true);
                    }
                    break;
            }

            for (int i = 0; i < itemOneAdapter.getCount(); i++) {
                BallItem ballItemOne = (BallItem) itemOneAdapter.getItem(i);
                for (int j = 0; j < randomBallOne.size(); j++) {
                    if (ballItemOne.getBallNum().equals(randomBallOne.get(j))) {
                        ballItemOne.setSelected(true);
                        break;
                    }
                }
            }
        }

        if (type.equals("plw") || type.equals("qxc")) {
            randomBallOne = MakeRandomUtil.getBall(10);
            randomBallTwo = MakeRandomUtil.getBall(10);
            randomBallThree = MakeRandomUtil.getBall(10);
            randomBallFour = MakeRandomUtil.getBall(10);
            randomBallFive = MakeRandomUtil.getBall(10);
            codeOne.add(randomBallOne.get(0));
            codeTwo.add(randomBallTwo.get(0));
            codeThree.add(randomBallThree.get(0));
            codeFour.add(randomBallFour.get(0));
            codeFive.add(randomBallFive.get(0));

            for (int i = 0; i < itemOneAdapter.getCount(); i++) {
                BallItem ballItemFour = (BallItem) itemOneAdapter.getItem(i);
                for (int j = 0; j < randomBallOne.size(); j++) {
                    if (ballItemFour.getBallNum().equals(randomBallOne.get(0))) {
                        ballItemFour.setSelected(true);
                        break;
                    }
                }
            }
            for (int i = 0; i < itemTwoAdapter.getCount(); i++) {
                BallItem ballItemFive = (BallItem) itemTwoAdapter.getItem(i);
                for (int j = 0; j < randomBallTwo.size(); j++) {
                    if (ballItemFive.getBallNum().equals(randomBallTwo.get(0))) {
                        ballItemFive.setSelected(true);
                        break;
                    }
                }
            }
            for (int i = 0; i < itemThreeAdapter.getCount(); i++) {
                BallItem ballItemFive = (BallItem) itemThreeAdapter.getItem(i);
                for (int j = 0; j < randomBallThree.size(); j++) {
                    if (ballItemFive.getBallNum().equals(randomBallThree.get(0))) {
                        ballItemFive.setSelected(true);
                        break;
                    }
                }
            }
            for (int i = 0; i < itemFourAdapter.getCount(); i++) {
                BallItem ballItemFour = (BallItem) itemFourAdapter.getItem(i);
                for (int j = 0; j < randomBallFour.size(); j++) {
                    if (ballItemFour.getBallNum().equals(randomBallFour.get(0))) {
                        ballItemFour.setSelected(true);
                        break;
                    }
                }
            }
            for (int i = 0; i < itemFiveAdapter.getCount(); i++) {
                BallItem ballItemFive = (BallItem) itemFiveAdapter.getItem(i);
                for (int j = 0; j < randomBallFive.size(); j++) {
                    if (ballItemFive.getBallNum().equals(randomBallFive.get(0))) {
                        ballItemFive.setSelected(true);
                        break;
                    }
                }
            }
        }

        if (type.equals("qxc")) {
            randomBallSix = MakeRandomUtil.getBall(10);
            randomBallSeven = MakeRandomUtil.getBall(10);
            codeSix.add(randomBallSix.get(0));
            codeSeven.add(randomBallSeven.get(0));

            for (int i = 0; i < itemSixAdapter.getCount(); i++) {
                BallItem ballItemSix = (BallItem) itemSixAdapter.getItem(i);
                for (int j = 0; j < randomBallSix.size(); j++) {
                    if (ballItemSix.getBallNum().equals(randomBallSix.get(0))) {
                        ballItemSix.setSelected(true);
                        break;
                    }
                }
            }
            for (int i = 0; i < itemSevenAdapter.getCount(); i++) {
                BallItem ballItemSeven = (BallItem) itemSevenAdapter.getItem(i);
                for (int j = 0; j < randomBallSeven.size(); j++) {
                    if (ballItemSeven.getBallNum().equals(randomBallSeven.get(0))) {
                        ballItemSeven.setSelected(true);
                        break;
                    }
                }
            }
        }

        countOne = randomBallOne.size();
        countTwo = randomBallTwo.size();
        countThree = randomBallThree.size();
        countFour = randomBallFour.size();
        countFive = randomBallFive.size();
        countSix = randomBallSix.size();
        countSeven = randomBallSeven.size();

        setNumberMoney(countOne, countTwo, countThree, countFour, countFive, countSix, countSeven);

        mBottomBar.setLeftText("清空");
    }

    //清空选中
    private void clearBall() {
        if (type.equals("pls") || type.equals("plw") || type.equals("qxc") || type.equals("sd")) {
            for (int i = 0; i < itemOneAdapter.getCount(); i++) {
                BallItem ballItemOne = (BallItem) itemOneAdapter.getItem(i);
                ballItemOne.setSelected(false);

                BallItem ballItemTwo = (BallItem) itemTwoAdapter.getItem(i);
                ballItemTwo.setSelected(false);

                BallItem ballItemThree = (BallItem) itemThreeAdapter.getItem(i);
                ballItemThree.setSelected(false);
            }
            for (int i = 0; i < itemFourAdapter.getCount(); i++) {
                BallItem item = (BallItem) itemFourAdapter.getItem(i);
                item.setSelected(false);
            }
        }

        if (type.equals("plw") || type.equals("qxc")) {
            for (int i = 0; i < itemOneAdapter.getCount(); i++) {
                BallItem ballItemFour = (BallItem) itemFourAdapter.getItem(i);
                ballItemFour.setSelected(false);

                BallItem ballItemFive = (BallItem) itemFiveAdapter.getItem(i);
                ballItemFive.setSelected(false);
            }
        }

        if (type.equals("qxc")) {
            for (int i = 0; i < itemOneAdapter.getCount(); i++) {
                BallItem ballItemSix = (BallItem) itemSixAdapter.getItem(i);
                ballItemSix.setSelected(false);

                BallItem ballItemSeven = (BallItem) itemSevenAdapter.getItem(i);
                ballItemSeven.setSelected(false);
            }
        }


        randomBallOne.clear();
        randomBallTwo.clear();
        randomBallThree.clear();
        randomBallFour.clear();
        randomBallFive.clear();
        randomBallSix.clear();
        randomBallSeven.clear();

        codeOne.clear();
        codeTwo.clear();
        codeThree.clear();
        codeFour.clear();
        codeFive.clear();
        codeSix.clear();
        codeSeven.clear();

        countOne = 0;
        countTwo = 0;
        countThree = 0;
        countFour = 0;
        countFive = 0;
        countSix = 0;
        countSeven = 0;


        itemOneAdapter.notifyDataSetChanged();
        itemTwoAdapter.notifyDataSetChanged();
        itemThreeAdapter.notifyDataSetChanged();
        itemFourAdapter.notifyDataSetChanged();
        itemFiveAdapter.notifyDataSetChanged();
        itemSixAdapter.notifyDataSetChanged();
        itemSevenAdapter.notifyDataSetChanged();
        // tv_number_money.setText(Html.fromHtml("共0注，<font color=red>0</font>元"));
        // tv_number_money.setText(Html.fromHtml("0注 , 0元"));
        tv_number_money.setVisibility(View.INVISIBLE);
        mBottomBar.setLeftText("机选");
    }

    boolean isTo;
    boolean restrict;

    private void addAllSelectToBetting() {
        if (type.equals("sd") || type.equals("pls")) {
            switch (modeState) {
                case 0:
                    if (codeOne.size() > 0 && codeTwo.size() > 0 && codeThree.size() > 0) {
                        addSelector();
                    }
                    break;
                case 1:
                    if (codeOne.size() > 0 && codeTwo.size() > 0) {
                        addSelector();
                    }
                    break;
                case 2:
                    if (codeOne.size() > 1) {
                        addSelector();
                    }
                    break;
                case 3:
                    if (codeOne.size() > 2) {
                        addSelector();
                    }
                case 4:
                    if(codeOne.size()>0){
                        addSelector();
                    }
                    break;
            }

        } else if (type.equals("plw") && codeOne.size() >= 1 && codeTwo.size() >= 1 && codeThree.size() >= 1 && codeFour.size() >= 1 && codeFive.size() >= 1) {
            addSelector();
        } else if (type.equals("qxc") && codeOne.size() >= 1 && codeTwo.size() >= 1 && codeThree.size() >= 1 && codeFour.size() >= 1
                && codeFive.size() >= 1 && codeSix.size() >= 1 && codeSeven.size() >= 1) {
            addSelector();
        }
    }

    private void addSelector() {
        formatBallNumber();

        if (isTo) {
            toActivity();
        }
        clearBall();

    }

    private void formatBallNumber() {
        //不断生成销毁，数据由codeOnes决定
        StringBuffer strBuffer = null;
        StringBuffer strBufferTwo = null;
        StringBuffer strBufferThree = null;
        StringBuffer strBufferFour = null;
        StringBuffer strBufferFive = null;
        StringBuffer strBufferSix = null;
        StringBuffer strBufferSeven = null;

        if (type.equals("sd") || type.equals("pls")) {
            switch (modeState) {
                //直选
                case 0:
                    strBuffer = new StringBuffer();
                    for (int j = 0; j < codeOne.size(); j++) {
                        strBuffer.append(codeOne.get(j));
                    }

                    strBufferTwo = new StringBuffer();
                    for (int j = 0; j < codeTwo.size(); j++) {
                        strBufferTwo.append(codeTwo.get(j));
                    }

                    strBufferThree = new StringBuffer();
                    for (int j = 0; j < codeThree.size(); j++) {
                        strBufferThree.append(codeThree.get(j));
                    }
                    ballNumber.add(strBuffer.toString() + "," + strBufferTwo.toString() + "," + strBufferThree.toString());

                    //填充mode
                    if (codeOne.size() > 1 || codeTwo.size() > 1) {
                        mode.add("直选 复式");
                    } else {
                        mode.add("直选 单式");
                    }
                    numMoney.add(num + "注" + " " + money + "元");
                    totalMoney += money;
                    totalNum += num;
                    number = 3;
                    break;
                //组三单式
                case 1:
                    strBuffer = new StringBuffer();
                    for (int j = 0; j < codeOne.size(); j++) {
                        strBuffer.append(codeOne.get(j));
                    }

                    strBufferTwo = new StringBuffer();
                    for (int j = 0; j < codeTwo.size(); j++) {
                        strBufferTwo.append(codeTwo.get(j));
                    }

                    ballNumber.add(strBuffer.toString() + strBuffer.toString() + strBufferTwo.toString());
                    mode.add("组三单式");
                    numMoney.add(num + "注" + " " + money + "元");
                    totalMoney += money;
                    totalNum += num;
                    number = 2;
                    break;
                //组三复式
                case 2:
                    strBuffer = new StringBuffer();
                    for (int j = 0; j < codeOne.size(); j++) {
                        if (j == codeOne.size() - 1) {
                            strBuffer.append(codeOne.get(j));
                        } else {
                            strBuffer.append(codeOne.get(j) + ",");
                        }
                    }
                    ballNumber.add(strBuffer.toString());
                    mode.add("组三复式");
                    numMoney.add(num + "注" + " " + money + "元");
                    totalMoney += money;
                    totalNum += num;
                    number = 2;
                    break;
                //组六
                case 3:
                    strBuffer = new StringBuffer();
                    for (int j = 0; j < codeOne.size(); j++) {
                        if (j == codeOne.size() - 1) {
                            strBuffer.append(codeOne.get(j));
                        } else {
                            strBuffer.append(codeOne.get(j) + ",");
                        }
                    }
                    ballNumber.add(strBuffer.toString());
                    mode.add("组六 复式");
                    numMoney.add(num + "注" + " " + money + "元");
                    totalMoney += money;
                    totalNum += num;
                    number = 3;
                    break;
                case 4:
                    strBuffer=new StringBuffer();
                    for (int i = 0; i < codeOne.size(); i++) {
                        strBuffer.append(codeOne.get(i)+",");
                    }
                    String code=strBuffer.substring(0,strBuffer.length()-1);
                    ballNumber.add(code);
                    mode.add("直选和值");
                    numMoney.add(num+"注"+" "+money+"元");
                    totalMoney+=money;
                    totalNum += num;
                    number=1;
                    break;
            }
        } else if (type.equals("plw")) {

            strBuffer = new StringBuffer();
            for (int j = 0; j < codeOne.size(); j++) {
                strBuffer.append(codeOne.get(j));
            }

            strBufferTwo = new StringBuffer();
            for (int j = 0; j < codeTwo.size(); j++) {
                strBufferTwo.append(codeTwo.get(j));
            }

            strBufferThree = new StringBuffer();
            for (int j = 0; j < codeThree.size(); j++) {
                strBufferThree.append(codeThree.get(j));
            }

            strBufferFour = new StringBuffer();
            for (int j = 0; j < codeFour.size(); j++) {
                strBufferFour.append(codeFour.get(j));
            }

            strBufferFive = new StringBuffer();
            for (int j = 0; j < codeFive.size(); j++) {
                strBufferFive.append(codeFive.get(j));
            }

            ballNumber.add(strBuffer.toString() + "," + strBufferTwo.toString() + "," + strBufferThree.toString() + "," + strBufferFour.toString() + "," + strBufferFive.toString());
            //填充mode
            if (codeOne.size() > 1 || codeTwo.size() > 1 || codeThree.size() > 1 || codeFour.size() > 1 || codeFive.size() > 1) {
                mode.add("排列五 复式");
            } else {
                mode.add("排列五 单式");
            }
            numMoney.add(num + "注" + " " + money + "元");
            totalMoney += money;
            totalNum += num;
            number = 5;

        } else if (type.equals("qxc")) {

            strBuffer = new StringBuffer();
            for (int j = 0; j < codeOne.size(); j++) {
                strBuffer.append(codeOne.get(j));
            }

            strBufferTwo = new StringBuffer();
            for (int j = 0; j < codeTwo.size(); j++) {
                strBufferTwo.append(codeTwo.get(j));
            }

            strBufferThree = new StringBuffer();
            for (int j = 0; j < codeThree.size(); j++) {
                strBufferThree.append(codeThree.get(j));
            }

            strBufferFour = new StringBuffer();
            for (int j = 0; j < codeFour.size(); j++) {
                strBufferFour.append(codeFour.get(j));
            }

            strBufferFive = new StringBuffer();
            for (int j = 0; j < codeFive.size(); j++) {
                strBufferFive.append(codeFive.get(j));
            }

            strBufferSix = new StringBuffer();
            for (int j = 0; j < codeSix.size(); j++) {
                strBufferSix.append(codeSix.get(j));
            }

            strBufferSeven = new StringBuffer();
            for (int j = 0; j < codeSeven.size(); j++) {
                strBufferSeven.append(codeSeven.get(j));
            }

            ballNumber.add(strBuffer.toString() + "," + strBufferTwo.toString() + "," + strBufferThree.toString() + ","
                    + strBufferFour.toString() + "," + strBufferFive.toString() + "," + strBufferSix.toString() + "," + strBufferSeven.toString());
            //填充mode
            if (codeOne.size() > 1 || codeTwo.size() > 1 || codeThree.size() > 1 || codeFour.size() > 1 || codeFive.size() > 1 || codeSix.size() > 1 || codeSeven.size() > 1) {
                mode.add("七星彩 复式");
            } else {
                mode.add("七星彩 单式");
            }
            numMoney.add(num + "注" + " " + money + "元");
            totalMoney += money;
            totalNum += num;
            number = 7;
        }

        mBottomBar.setBettingNumber(totalNum);
    }

    //不同玩法随机球数量
    int number;
    //球
    private ArrayList<String> ballNumber = new ArrayList<>();
    //玩法及模式
    private ArrayList<String> mode = new ArrayList<>();
    //注数及金额
    private ArrayList<String> numMoney = new ArrayList<>();
    //总金额
    private int totalMoney;
    //总注数
    private int totalNum;

    private void toActivity() {
        Intent intent = new Intent(this, BetConfirmActivity.class);
        intent.putExtra("number", number);
        intent.putExtra("type", type); //彩种
        intent.putExtra("totalMoney", totalMoney);
        intent.putExtra("totalNum", totalNum);
        intent.putStringArrayListExtra("ballNumber", ballNumber);
        intent.putStringArrayListExtra("mode", mode);
        intent.putStringArrayListExtra("numMoney", numMoney);
        startActivityForResult(intent, 0);

        Log.e(TAG, "number=" + number);
        Log.e(TAG, "type=" + type);
        Log.e(TAG, "totalMoney=" + totalMoney);
        Log.e(TAG, "totalNum=" + totalNum);
        for (int i = 0; i < ballNumber.size(); i++) {
            Log.e(TAG, "ballNumber=" + ballNumber.get(i));
            Log.e(TAG, "mode=" + mode.get(i));
            Log.e(TAG, "numMoney=" + numMoney.get(i));
        }

    }

    public void setMissData(MissDataBean missData) {
        //这里的话，我们是需要设置遗漏和最近10期的开奖情况；
        mPLS_sd_qxca_lotteryAdapter = new PLS_SD_QXCA_LotteryAdapter(this);
        mPLS_sd_qxca_lotteryAdapter.setData(missData.getCodes());
        mLvHistory.setAdapter(mPLS_sd_qxca_lotteryAdapter);
        //这里的话，我们要做的一个操作就是测量

        int height = measureListViewWrongHeight(mLvHistory);

        mLvHistory.getLayoutParams().height = height;
        mLvHistory.requestLayout();
        mDrawerLayout.measureInnerLayout();

        //这里我们设置遗漏的数据；

        mOmission = missData.getOmission();
        //这里我们是需要对其进行一个判断的；


        if (type.equals("pls") || type.equals("plw") || type.equals("qxc") || type.equals("sd")) {
            itemOneAdapter.addMissDataInfo(mOmission.getM0());
            itemTwoAdapter.addMissDataInfo(mOmission.getM1());
            itemThreeAdapter.addMissDataInfo(mOmission.getM2());

            itemFourAdapter.addMissDataInfo(mOmission.getM6());
        }
        if (type.equals("plw") || type.equals("qxc")) {
            itemFourAdapter.addMissDataInfo(mOmission.getM3());
            itemFiveAdapter.addMissDataInfo(mOmission.getM4());
        }
        if (type.equals("qxc")) {
            itemSixAdapter.addMissDataInfo(mOmission.getM5());
            itemSevenAdapter.addMissDataInfo(mOmission.getM5());
        }

        itemOneAdapter.notifyDataSetChanged();
        itemTwoAdapter.notifyDataSetChanged();
        itemThreeAdapter.notifyDataSetChanged();
        itemFourAdapter.notifyDataSetChanged();
        itemFiveAdapter.notifyDataSetChanged();
        itemSixAdapter.notifyDataSetChanged();
        itemSevenAdapter.notifyDataSetChanged();
    }


    private class ViewHolder {
        TextView ball_num;
        TextView tv_missData;
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (data == null) return;
        switch (resultCode) {
            //继续选号
            case 0:
                ballNumber = data.getStringArrayListExtra("ballNumber");
                mode = data.getStringArrayListExtra("mode");
                numMoney = data.getStringArrayListExtra("numMoney");
                totalMoney = data.getIntExtra("totalMoney", totalMoney);
                totalNum = data.getIntExtra("totalNum", totalNum);


                mBottomBar.setBettingNumber(totalNum);
                break;
            //清除选号
            case 1:
                clearAllBetting();
                break;
            case -1:
                this.finish();
                break;
        }
    }

    private void clearAllBetting() {
        ballNumber.clear();
        mode.clear();
        numMoney.clear();
        totalMoney = 0;
        totalNum = 0;
        mBottomBar.setBettingNumber(totalNum);
    }

    @Override
    protected void onPause() {
        super.onPause();
        mShakeUtils.unRegister();
    }


    int topHeight = 0;

    public int measureListViewWrongHeight(ListView listView) {
        ListAdapter listAdapter = listView.getAdapter();
        if (listAdapter == null) {
            return 0;
        }
        int totalHeight = 0;
        for (int i = 0; i < listAdapter.getCount(); i++) {
            View listItem = listAdapter.getView(i, null, listView);
            listItem.measure(0, 0);
            totalHeight += listItem.getMeasuredHeight();
        }

        ViewGroup.LayoutParams params = listView.getLayoutParams();
        topHeight = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
        params.height = topHeight;
        listView.setLayoutParams(params);
        return totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
    }

    /**
     * 这里是从未选中到选中的一个缩放动画；
     */
    public void startBallAnimation(View view) {
        //一个缩放动画；
        AnimatorSet animatorSet = new AnimatorSet();

        ObjectAnimator animator1 = ObjectAnimator.ofFloat(view, "scaleY", 1f, 0.8f, 1f);
        ObjectAnimator animator2 = ObjectAnimator.ofFloat(view, "scaleX", 1f, 0.8f, 1f);

        animatorSet.playTogether(animator1, animator2);
        animatorSet.setDuration(200);
        animatorSet.start();
    }

    @Override
    protected void sendRandom(Intent intent) {
        //机选
        int num = intent.getIntExtra("num", 0);
        if (num > 0) {
            clearAllBetting();
            //开始机选
            for (int i = 0; i < num; i++) {
                randomSelect();
                addAllSelectToBetting();
            }
            intent.setAction(Constant_Result.EXECRANDOMLOTTERYNUM);
            intent.putExtra("number", number);
            intent.putExtra("type", type); //彩种
            intent.putExtra("totalMoney", totalMoney);
            intent.putExtra("totalNum", totalNum);
            intent.putStringArrayListExtra("ballNumber", ballNumber);
            intent.putStringArrayListExtra("mode", mode);
            intent.putStringArrayListExtra("numMoney", numMoney);
            sendBroadcast(intent);
        }
    }
}
